<div class="row">
<div class="col-sm-12" id="data-admin-id" data-admin-id="<?php echo $result['id'];?>">
	<form action="<?php echo DOMAIN_NURSERY?>/admin/edit/<?php echo $result['id'];?>" method="post"  id='add_user_submit'>

	<table id="inputs-table" class="table table-striped table-bordered table-hover" >
		<tr>
			<td class="text-right" width="100"><span class="red">*</span>用户名：</td>
			<td>
				<input type="text" name="username"  id="data-admin-username"
					   value="<?php echo $result['username']?>"  style="width: 30%" maxlength="20" required>
				<label class="red" id="data-role-name-error"><?php echo form_error('username')?></label>
			</td>
		</tr>
		<tr>
			<td class="text-right"><span class="red"></span>密码：</td>
			<td>
				<input type="password" class="table_09_input bg-fff"  name="pass"  id="data-admin-pass"
					   value="" style="width: 30%" maxlength="20">
				<label class="red" id="data-role-pass-error"></label>
			</td>
		</tr>
		
		<tr>
			<td class="text-right" width="100">管理员昵称：</td>
			<td style="height: 50px;">
				<input type="text" name="nickname"  id="data-admin-username"
					   value="<?php echo $result['nickname']?>" maxlength="40">
				<label class="red" id="data-role-nickname-error"><?php echo form_error('nickname')?></label>
			</td>
		</tr>
			
		<tr>
			<td class="text-right"><span class="red">*</span>选择角色：</td>
			<td>
				<select name='rid'>
					<?php foreach( $roles as $e ):?>
					<option value=<?php echo $e['id']?>  <?php if( $e['id'] == $result['rid']) echo "selected";?>><?php echo $e['name']?></option>
					<?php endforeach;?>
				</select>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<button class="btn btn-info btn-sm" type="submit">提交</button>
			</td>
		</tr>
	</table>
</form>
</div>

<script type="text/javascript">

	$(document).on('keyup', '#data-admin-username', function () {

		var admin_name=$('#data-admin-username').val();
		var admin_id=$('#data-admin-id').attr('data-admin-id');
		var url='<?php echo DOMAIN_MAIN?>/api/npermissions/check_admin_name';
		var params={
			admin_name:admin_name,
			admin_id:admin_id
		};

		$.get(url, params, function (data) {
			if(data.state=='success'){
				var new_dom='管理员名称已存在，请重新填写！';
				$("#data-role-name-error").html(new_dom);
				return false;
			}else{
				$("#data-role-name-error").html('');
				return true;
			}

		},'json');



	});

	$(document).on('keyup', '#data-admin-pass', function () {

		var admin_pass=$('#data-admin-pass').val();
		var url='<?php echo DOMAIN_NURSERY?>/api/npermissions/check_admin_pass';
		var params={
			admin_pass:admin_pass
		};

		$.get(url, params, function (data) {
			if(data.state=='success'){
				if(data.error_type==1){
					var new_dom='管理员密码须大于6位，请继续输入！';
				}else if(data.error_type==2){
					var new_dom='管理员密码须小于30位，请重新填写！';
				}

				$("#data-role-pass-error").html(new_dom);
				return false;
			}else{
				$("#data-role-pass-error").html('');
				return true;
			}

		},'json');



	});
</script>